<%@page import="wt.session.SessionServerHelper"%>
<%@page import="com.ptc.core.agreements.commands.AgreementsCommands"%>
<%@page import="com.ptc.netmarkets.model.NmOid"%>
<%@page import="wt.workflow.work.WorkItem"%>
<%@page import="wt.fc.ReferenceFactory"%>
<%@page import="wt.vc.VersionControlHelper"%>
<%@page import="wt.fc.QueryResult"%>
<%@page import="ext.drawing.BorrowUtil"%>
<%@page import="ext.drawing.bean.DrawingsBorrowBean"%>
<%@page import="wt.doc.WTDocument"%>
<%@page import="wt.fc.WTObject"%>
<%@page import="ext.drawing.BorrowWorkflowUtil"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="wt.method.RemoteMethodServer,
	                 ext.workflow.WorkFlowUtil,
					 java.util.*,
					 java.lang.*,
					 wt.project.*,
					 wt.workflow.engine.*,
					 wt.org.*
					 "%>
<html>
<head>
<script type="text/javascript" src="../js/jquery-easyui-1.6.7/jquery.min.js"></script>
<%
	boolean flag = SessionServerHelper.manager.setAccessEnforced(false);// 忽略权限
	String oid = request.getParameter("oid");
 	String states = "";
	WfProcess wfPro = WorkFlowUtil.GetWfProcess(oid);
	ProcessData processData = wfPro.getContext();
	String version = (String)processData.getValue("versionName");
	Boolean isSuperEdit =(Boolean)processData.getValue("isSuperEdit");
	Boolean isOwerEdit = (Boolean)processData.getValue("isOwerEdit");
	if(isSuperEdit == false && isOwerEdit == false){
		states = BorrowUtil.BORROW;
	}else{
		states = BorrowUtil.REVIEW;
	}
	WTObject wtObject = BorrowWorkflowUtil.getPBO(wfPro);
	WTDocument doc = null;
	if (wtObject != null && wtObject instanceof WTDocument) {
		doc = (WTDocument) wtObject;
	}
	int dayNum = 0;
	String name = "";
	String cause = "";
	String reason ="";
	List list = new ArrayList();
	if (doc != null) {
		List<DrawingsBorrowBean> Drawings = BorrowUtil.getDrawingBorrowByNumberAndName(doc.getNumber(), wfPro.getCreator().getName(),version);// 通过文档编号和人员，查询数据表
		if (Drawings.size() != 0) {
			for (int i = 0; i < Drawings.size(); i++) {
				DrawingsBorrowBean db = Drawings.get(i);
				String state = db.getBorrowState();
				if (states.equals(state)) {
					version = db.getDrawingsBorrowVersion();
					dayNum = Integer.parseInt(db.getBorrowDate());
					name = db.getDrawingsBorrowName();
					cause = db.getAttr1();
					reason = db.getAttr2();
				}
			}
		}
		//获取所有已发布版本的文档  modify by lilin 09点12分
		QueryResult qr=VersionControlHelper.service.allIterationsOf(doc.getMaster());
		while ( qr.hasMoreElements() ) {
			WTDocument docTemp = (WTDocument) qr.nextElement();
			String state = docTemp.getState().getState().getStringValue();
			if ("wt.lifecycle.State.RELEASED".equals(state)) {// 已发布状态
				String partVersion = BorrowWorkflowUtil.getVersion( docTemp ) ;
				list.add(partVersion);
			}
		}
	}
	SessionServerHelper.manager.setAccessEnforced(flag);// 关闭权限
%>
<style type="text/css">
#top{
	height: 100px;
	color: #464646;
	font-size: 11px;
	font-weight: bold;
	font-family:verdana;
}
#topDocName{
	margin-left: 73px;
	margin-top: 8px;
	}
#docName{
	font-weight: normal;
}
#cause{
	font-weight: normal;
}
#reason{
	font-weight: normal;
}
#top2{
	margin-left: 73px; 
	margin-top: 5px;
}
#docNumber{
	font-weight: normal;
}
#topdocVersion{
	margin-left: 73px; 
	margin-top: 5px;
}
#docVer{
	width:50px;
	font-weight: normal;
}
#topDay{
	margin-left: 60px; 
	margin-top: 5px;
}
#day{
	font-weight: normal;
}
#topCause{
	margin-left: 84px; 
	margin-top: 5px;
}
#topReason{
	margin-left: 84px; 
	margin-top: 5px;
}
</style>

</script>
</head>
<body>
	    <div id="top">
	       <div id="topDocName">
	       	 <span>图文档名称:</span>
	         <span id="docName"><%=name %></span>
	       </div>
<!-- 	       <div id="top2"> -->
<!-- 	         <span>图档编码:</span> -->
<!-- 	         <a id="docNumber" href="111111">111111</a> -->
<!-- 	       </div> -->
	       <div id="topdocVersion">
	                         图文档版本:
	           <%if(isOwerEdit == false ){ %>
	           		<select id="docVer" name="docVer" disabled="disabled">
	           <%}else{ %>
	           		<select id="docVer" name="docVer" >
	           <%} %>
	            	<%for(int i=0;i<list.size();i++){%>
 					<%if(version.equals(list.get(i))){%>
					<option value="<%=list.get(i) %>" selected="selected"><%=list.get(i) %></option>
					<%}else{ %>
					<option value="<%=list.get(i) %>"><%=list.get(i) %></option>
			   	<%} } %>
	           </select>
	       </div>
	       <div id="topDay">
	           <span>借阅时间(天):</span>
	           <span id="day" name="day"><%=dayNum %>天</span> 
	       </div>
	       <div id="topCause">
	           <span>申请原因:</span>
	           <span id="cause" name="cause"><%=cause %></span> 
	       </div>
	       <div id="topReason">
	           <span>申请理由:</span>
	           <span id="reason" name="reason"><%=reason %></span> 
	       </div>
	    </div>
</body>
</html>